<?php

namespace App\Console\Commands;

use App\Record;
use Illuminate\Console\Command;

class RecordCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'record';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
      $record=  Record::chunkById(100,function ($records){
          $fileName="example.txt";
          foreach ($records as $record){
              $file = fopen($fileName, "a") or die("无法打开文件！");
              $content=$record->content;
              fwrite($file, $content);
              fclose($file);
              $this->info($record->record_id);
          }
      });

    }
}
